const comment = require("../../modules/comment");

const addComment = async (req, res) => {
  try {
    const { user_id, md_id, content } = req.body;
    if (!user_id || !md_id || !content) {
      res.status(200).json({ msg: "参数缺失", code: 400 });
      return;
    }
    await comment.addComment(req.body);
    res.status(200).json({ msg: "评论成功", code: 200 });
  } catch (err) {
    res.status(200).json({ msg: "服务器返回错误，请稍后再试", code: 500 });
  }
};

const getComment = async (req, res) => {
  try {
    const { user_id, md_id } = req.query;
    if (!user_id || !md_id) {
      res.status(200).json({ msg: "参数缺失", code: 400 });
      return;
    }
    const list = await comment.getComment(req.query);
    res.status(200).json({ msg: "评论成功", code: 200, list });
  } catch (err) {
    res.status(200).json({ msg: "服务器返回错误，请稍后再试", code: 500 });
  }
};

module.exports = {
  addComment,
  getComment,
};
